#include <stdio.h>
#include <curl/curl.h>
#include <string.h>

static size_t write_func(const void *ptr, size_t size,
                         size_t n, void *user_ptr)
{
    memcpy(user_ptr, ptr, size * n);
    return size * n;
}

int main(void)
{
    CURL *curl;
    curl = curl_easy_init();
    long return_code;
    char buf[4096];

    curl_easy_setopt(curl, CURLOPT_URL, "http://192.168.23.10:8000/fileinfo");
    curl_easy_setopt(curl, CURLOPT_WRITEDATA, buf);
    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_func);

    CURLcode ret = curl_easy_perform(curl);

    // 首先根据ret判断请求是否成功
    if (ret == CURLE_OK)
    {
        curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &return_code);
        if (return_code == 200)
        {
            printf("%s\n", buf);
            curl_easy_cleanup(curl);
            return 0;
        }
    }
    curl_easy_cleanup(curl);

    return -1;
}
